﻿namespace TfsCloudDeploy.Workflow.Core
{
    using System;
    using System.ComponentModel;
    using System.Globalization;

    /// <summary>
    /// Converter for the DatabaseServerInstance class.
    /// </summary>
    public class DatabaseServerInstanceConverter : ExpandableObjectConverter
    {
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            return ((destinationType == typeof(string)) || base.CanConvertTo(context, destinationType));
        }

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (!(destinationType == typeof(string)) || !(value is DatabaseServerInstance))
            {
                return base.ConvertTo(context, culture, value, destinationType);
            }
            DatabaseServerInstance databaseServerInstance = (DatabaseServerInstance)value;
            return databaseServerInstance.ToString();
        }
    }
}
